package org.dynamo.database.reverse.run.internal;

/*******************************************************************************
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Jean Neveux - initial API and implementation
 *******************************************************************************/

import org.dynamo.database.reverse.config.internal.SQLDTPConverter;
import org.dynamo.database.reverse.run.IConvertDatabase;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.datatools.modelbase.sql.schema.Schema;

public class ConvertDatabaseImpl implements IConvertDatabase {
	private static IConvertDatabase instance;	
	private IFile configfile;
	
	public static IConvertDatabase getInstance() {
		if(instance == null) 
			instance = new ConvertDatabaseImpl();
		return instance;
	}

	@Override
	public void run(final Schema schema, IProgressMonitor monitor, final String modelPath) {
		monitor.worked(1);
		monitor.setTaskName("Starting database conversion"); //$NLS
		SQLDTPConverter sdtp = new SQLDTPConverter();
		sdtp.setConfigfile(configfile);
		sdtp.perform(modelPath, schema);
		monitor.worked(1);
		monitor.setTaskName("Finished converting"); //$NLS
	}

	@Override
	public void setConfigFile(IFile createDefaultConfigurationFile) {
		configfile = createDefaultConfigurationFile;
	}
}